package crp.services.api.graphql.models;

import crp.core.portal.domain.models.NewsArticleEntity;
import crp.core.shared.LifecycleStatus;
import com.qwlabs.storage.models.StorageObject;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import org.eclipse.microprofile.graphql.Id;
import org.eclipse.microprofile.graphql.Ignore;
import org.eclipse.microprofile.graphql.Type;

import javax.validation.constraints.NotNull;
import java.time.Instant;

@Type("NewsArticle")
@Builder
@Getter
@AllArgsConstructor
public class NewsArticlePayload {
    @Id
    @NotNull
    private final String id;
    @NotNull
    private final String title;
    @NotNull
    private final String content;
    @NotNull
    private final Instant createdAt;
    @Ignore
    private final StorageObject cover;
    @NotNull
    private final LifecycleStatus status;

    public static NewsArticlePayload of(NewsArticleEntity entity) {
        return NewsArticlePayload.builder()
                .id(entity.getId())
                .title(entity.getTitle())
                .content(entity.getContent())
                .cover(entity.getCover())
                .createdAt(entity.getCreatedAt())
                .status(entity.getStatus())
                .build();
    }
}
